static void program_usage(const char *progname)
{
	printf("Usage: %s [OPTION]...\n", progname);
	printf("This program used to connect to server and send RPi's temperature by TLV protocal.\n");
	printf("\nMandatory arguments to long options are mandatory for short options too:\n");
	printf(" -H[Host    ]  Specify host server address and port, foramt as \"127.0.0.1:9000\"\n");
	printf(" -d[debug   ]  Running in debug mode\n");
	printf(" -h[help    ]  Display this help information\n"); 
	printf(" -v[version ]  Display the program version\n");
	printf("\n");

	banner();
	return ;
}

/* 打印版本信息*/
static void banner(void)
{
	printf("Version %s build on %s %s\n", PROG_VERSION, __DATE__, __TIME__); 
	printf("Copyright (C) 2020 Hakuura.\n\n");

	return ;
}

int main(int argc, char *argv[])
{
    struct option long_options[] = { 
        {"Host", required_argument, NULL, 'H'}, 
        {"debug", no_argument, NULL, 'd'}, 
        {"version", no_argument, NULL, 'v'}, 
        {"help", no_argument, NULL, 'h'}, 
        {NULL, 0, NULL, 0}
    };
    
    progname = basename(argv[0]); /* get program name */

    /* parser the command line parameters */ 
    while ((opt = getopt_long(argc, argv, "H:dvh", long_options, NULL)) != -1) 
    { 
        switch (opt) 
        {
            case 'H':
                host=optarg;
                break;
 
            case 'd': /* set debug running */
                debug = 1;
                log_level= LOG_LEVEL_DEBUG;
                log_file = NULL;  /* use standard output */
                break;
 
            case 'v':  /* print software version */
                banner();
                return EXIT_SUCCESS; 
 
            case 'h':  /* print help information */
                program_usage(progname);
                return 0; 
 
            default: 
                break; 
        } 
    }

    if( !host )
    {
        printf("ERROR: No argument specify host server address and port, please refer to usage\n");
        program_usage(progname);
    }

    /* check program already running or not, if already running then exit, or set running as daemon */
    if( !debug )
    {
        if( check_run(progname) )
        {
            printf("Programe is already running, exit now.\n");
            return -1;
        }
 
        if(daemon(1,1)<0)
		{
			perror("error daemon.../n"); 
			return 0;
		}
        else
		{
			printf("Program %s is running at the backgroud now\n", progname);
		}
    }

    /* initial and open logger system */
    if( logger_init(&logger, log_file, log_level, 512)<0 || logger_open()<0 )
    {
        printf("ERROR: Initialise logger system failure\n");
        return 2;
    }
 
    log_nrml("Program start running\n");

    /* initital the database */ 
    if( clidb_init("./tlv_client.db")< 0) 
    {
        log_err("initial sqlite database failure\n");
        return 3;
    }

    while( !g_sigstop )
    {
        time(&cur_time);
        last_time = 0;
        rv = 0 ;
        if（cur_time-last_time>30）
        {
                log_nrml("start collecting and packing relevent information now.\n");
                rv = ds18b20_get_temperature(&temp);

                if(rv = 0)
                {
                    /* convert time_t to tm format  */
                    tm=localtime(&cur_time);
                    last_time = cur_time;

                    /* pack sn,temperature and time in TLV format  */
                    packtlv_msg(&tlv, RPI_SN, temp, tm);
                    logger_dump(LOG_LEVEL_DEBUG,tlv.buf, tlv.len);

                    /* this message need to be transmit and saved in database if send failure */
                    tlv.flag = TLV_SAVEDB;
                }                
                else
                {
                        log_err("RPI get temperature failure\n");
                }
        }

        /* not connect to server */
        if(sock_fd < 0)
        {   
                /* start connecting to server */
                if((sock_fd=client_init(serv_port, serv_ip)) < 0)    
                {
                    log_err("connect to server failure: %s\n", strerror(errno));
                    if(!(save_into_db(db,&tlv_data)))
                    {
                            printf("write into data db successfuly\n");
                            tlv.flag = NOSAVB;
                    }
                    continue;  
                }
        }

        

    }

}